package com.crx.springbootinit.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.crx.springbootinit.annotation.AuthCheck;
import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.logApi.LogApiPageDTO;
import com.crx.springbootinit.model.dto.love.LovePageDTO;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.entity.LogApi;
import com.crx.springbootinit.model.vo.logApi.LogApiPageVO;
import com.crx.springbootinit.model.vo.love.LoveMyPostVO;
import com.crx.springbootinit.service.ILogApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 谢杭延
 * @Date 2024-11-01 12:57
 */
@RestController
@RequestMapping("/admin/logApi")
@RequiredArgsConstructor
@Api(tags = "后台接口日志模块接口")
@Slf4j
public class LogApiAdminController {

    private final ILogApiService logApiService;

    @DeleteMapping("/delete/{ids}")
    @ApiOperation("删除接口日志")
    @AuthCheck
    public BaseResponse<Void> deleteLogApi(@ApiParam("接口日志id列表") @PathVariable List<String> ids){
        logApiService.removeByIds(ids);
        return BaseResponse.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询接口日志列表")
    @AuthCheck
    public BaseResponse<PageVO<LogApiPageVO>> queryLogApiPage(LogApiPageDTO logApiPageDTO){
        PageVO<LogApiPageVO> pageVO = logApiService.queryLogApiPage(logApiPageDTO);
        return BaseResponse.success(pageVO);
    }
    @GetMapping("/{id}")
    @ApiOperation("查询接口日志详情")
    @AuthCheck
    public BaseResponse<LogApiPageVO> queryLogApiById(@ApiParam("接口日志id") @PathVariable String id){
        LogApi logApi = logApiService.getById(id);
        LogApiPageVO logApiPageVO = BeanUtil.copyProperties(logApi, LogApiPageVO.class);
        return BaseResponse.success(logApiPageVO);
    }


}
